import 'package:flutter/material.dart';
// import 'package:video_player/video_player.dart';
import 'package:xinxuan/common/appbar_util.dart';
import 'package:xinxuan/common/button_util.dart';
import 'package:xinxuan/common/dialogs/cancel_account_dialog.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:xinxuan/common/dialogs/del_dialog.dart';
import 'package:xinxuan/common/info_item.dart';
import 'package:xinxuan/common/dialogs/input_dialog_util.dart';
import 'package:xinxuan/common/network_image_util.dart';
import 'package:xinxuan/common/scroll_configuration_common.dart';
import 'package:xinxuan/controllers/common_page_controller.dart';
import 'package:xinxuan/controllers/home_controller/home_page_controller.dart';
import 'package:xinxuan/controllers/my_controller/my_page_controller.dart';
import 'package:xinxuan/router/app_routers.dart';
import 'package:get/get.dart';
import 'package:xinxuan/utils/color_util.dart';

class MyInfoPage extends StatelessWidget {

  final CommonPageController commonPageController = Get.find();
  final MyPageController myPageController = Get.find();
  final HomePageController homePageController = Get.find();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: pageBgColor,
      appBar: AppBarUtil(
        title: '个人信息',
        backgroundColor: pageBgColor,
      ),
      body: GetBuilder<CommonPageController>(
        builder: (controller) {
          return ScrollConfigurationCommon(child: ListView(
            children: [
              InfoItem(
                title: '头像', 
                child: NetworkImageUtil(
                  url: commonPageController.userData.value.avatar ?? '', 
                  nickname: '${commonPageController.userData.value.nickname}',
                  width: 50.w, 
                  height: 50.w,
                  borderRadius: 50.w,
                  showShadow: false,
                ), 
                showRigth: false,
                onTap: () {}
              ),
              InfoItem(
                title: '姓名', 
                child: Text(
                  '${commonPageController.userData.value.nickname}',
                  style: TextStyle(
                    color: textSubtitleColor,
                    fontSize: 16.sp
                  ),
                ), 
                onTap: () {
                  Get.dialog(StatefulBuilder(
                    builder: (context, setButtomSheetState) {
                      return InputDialogUtil(
                        title: '修改名称',
                        hintText: '请输入昵称',
                        maxLength: 10,
                        defaultValue: '${commonPageController.userData.value.nickname}',
                        onChenge: (value) {
                          commonPageController.nickname = value;
                        },
                        onSubmit: () {
                          commonPageController.editUserName();
                        }
                      );
                    }
                  ));
                }
              ),
              InfoItem(
                title: '手机号', 
                child: Text(
                  '${commonPageController.userData.value.mobile}',
                  style: TextStyle(
                    color: textSubtitleColor,
                    fontSize: 16.sp
                  ),
                ), 
                showRigth: false,
                onTap: () {}
              ),
              InfoItem(
                title: '收货地址', 
                child: Container(), 
                showBorder: false,
                onTap: () {
                  Get.toNamed(
                    '${AppRouters.COMMON_PAGE}${AppRouters.MY_INFO_PAGE}${AppRouters.ADDRESS_LIST_PAGE}',
                    arguments: {
                      'isSelectAddress': false
                    }
                  );
                }
              ),
              SizedBox(height: 12.h),
              InfoItem(
                title: '实名认证', 
                child: Container(), 
                onTap: () {
                  Get.toNamed('${AppRouters.COMMON_PAGE}${AppRouters.MY_INFO_PAGE}${AppRouters.AUTHENTICATION_PAGE}');
                }
              ),
              // InfoItem(
              //   title: '收款信息管理', 
              //   child: Container(), 
              //   onTap: () {
              //     Get.toNamed('${AppRouters.COMMON_PAGE}${AppRouters.MY_INFO_PAGE}${AppRouters.BANK_CARD_LIST_PAGE}');
              //   }
              // ),
              // InfoItem(
              //   title: '我的银行卡', 
              //   child: Container(), 
              //   onTap: () {
              //     Get.toNamed('${AppRouters.COMMON_PAGE}${AppRouters.MY_INFO_PAGE}${AppRouters.PAY_BANK_LIST_PAGE}');
              //   }
              // ),
              // InfoItem(
              //   title: '汇聚支付', 
              //   child: Container(), 
              //   onTap: () {
              //     Get.toNamed('${AppRouters.COMMON_PAGE}${AppRouters.MY_INFO_PAGE}${AppRouters.BANK_PAGE}');
              //   }
              // ),
              // InfoItem(
              //   title: '支付密码修改', 
              //   child: Container(), 
              //   onTap: () {
              //     Get.toNamed('${AppRouters.COMMON_PAGE}${AppRouters.MY_INFO_PAGE}${AppRouters.UPDATE_PAY_PASSWORD_PAGE}');
              //   }
              // ),
              InfoItem(
                title: '登录密码修改', 
                child: Container(), 
                onTap: () {
                  Get.toNamed('${AppRouters.COMMON_PAGE}${AppRouters.MY_INFO_PAGE}${AppRouters.UPDATE_PASSWORD_PAGE}');
                }
              ),
              SizedBox(height: 12.h),
              InfoItem(
                title: '我的微信号', 
                child: Container(), 
                onTap: () {
                  Get.dialog(StatefulBuilder(
                    builder: (context, setButtomSheetState) {
                      return InputDialogUtil(
                        title: '修改微信号',
                        hintText: '请输入微信号',
                        defaultValue: '${commonPageController.userData.value.wechat}',
                        maxLength: 25,
                        onChenge: (value) {
                          commonPageController.wechat = value;
                        },
                        onSubmit: () {
                          commonPageController.editUserWechat();
                        }
                      );
                    }
                  ));
                }
              ),
              InfoItem(
                title: '关于我们', 
                child: Container(), 
                showBorder: false,
                onTap: () {
                  Get.toNamed('${AppRouters.COMMON_PAGE}${AppRouters.MY_INFO_PAGE}${AppRouters.ABOUT_US_PAGE}');
                }
              ),
              SizedBox(height: 12.h),
              InfoItem(
                title: '版本更新', 
                child: Text(
                  '版本${commonPageController.appVersion}',
                  style: TextStyle(
                    color: textSubtitleColor,
                    fontSize: 16.sp
                  ),
                ), 
                onTap: () {
                  commonPageController.checkAppVersion();
                }
              ),
              SizedBox(height: 12.h),
              InfoItem(
                title: '注销账号', 
                child: Container(), 
                showBorder: false,
                onTap: () {
                  Get.dialog(CancelAccountDialog());
                }
              ),
              SizedBox(height: 12.h),
            ],
          ));
        },
      ),
      bottomNavigationBar: BottomAppBar(
        child: Container(
          height: 56.h,
          alignment: Alignment.center,
          padding: EdgeInsets.symmetric(horizontal: 12.w),
          child: ButtonUtil(
            text: '退出登录', 
            textColor: textBlackColor,
            bgColors: [
              pageBgColor,
              pageBgColor
            ],
            fontSize: 14.sp, 
            borderRadius: 18.w, 
            height: 36.h, 
            onTop: () {
              Get.dialog(DelDialog(title: '退出', message: '是否要退出登录？', onTap: () {
                myPageController.titleBarOpacity.value = 0.0;
                commonPageController.logOut();
              }));
            }
          ),
        ),
      ),
    );
  }
}

// class MyInfoPage extends StatefulWidget {

//   @override
//   _MyInfoPageState createState() => _MyInfoPageState();
// }

// class _MyInfoPageState extends State<MyInfoPage> {

//   VideoPlayerController? _controller;

//   @override
//   void initState() {
//     super.initState();
//     _controller = VideoPlayerController.network(
//         'https://vd4.bdstatic.com/mda-mhmccajvqqq6fs83/sc/cae_h264/1629622455645825022/mda-mhmccajvqqq6fs83.mp4?v_from_s=hkapp-haokan-hna&auth_key=1642504494-0-0-66629cd06ee0bf8cbb2664fde54de2f5&bcevod_channel=searchbox_feed&pd=1&pt=3&logid=2693984263&vid=14005544185206936375&abtest=&klogid=2693984263')
//         ..initialize().then((_) {
//       // Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
//       setState(() {});
//     });
//   }

//   @override
//   Widget build(BuildContext context) {
//     return Scaffold(
//       appBar: AppBarUtil(title: '个人中心'),
//       body: Column(
//         children: [
//           AspectRatio(
//             aspectRatio: _controller!.value.aspectRatio,
//             child: VideoPlayer(_controller!),
//           ),
//           Container(
//             margin: EdgeInsets.only(top: 32.h),
//             padding: EdgeInsets.symmetric(horizontal: 32.w),
//             child: ButtonUtil(
//               text: '播放', 
//               fontSize: 14.sp,
//               borderRadius: 30.w, 
//               height: 36.h, 
//               onTop: () {
//                 _controller!.value.isPlaying ? _controller!.pause() : _controller!.play();
//               }
//             ),
//           )
//         ],
//       ),
//     );
//   }

//   @override
//   void dispose() {
//     _controller?.dispose();
//     super.dispose();
//   }
// }